package com.zsh.weather.ln.home.ui.search.model

import com.zsh.weather.ln.base.OnLoadDataListener
import com.zsh.weather.ln.bean.CityHotList
import com.zsh.weather.ln.bean.CitySearchList
import com.zsh.weather.ln.https.BaseCallBack
import com.zsh.weather.ln.https.RequestManager
import com.zsh.weather.ln.utils.Constant
import okhttp3.Call

class SearchModel {
    fun getHotCitys(onLoadDataListener: OnLoadDataListener){
        var params: HashMap<String, String> = hashMapOf()
        params.put("key", Constant.key)
        RequestManager().doGet(Constant.url_top, null, params)
            .execute(object : BaseCallBack<CityHotList>(CityHotList::class.java) {
                override fun success(call: Call?, data: CityHotList) {
                    onLoadDataListener.success(data)
                }

                override fun fail(error: String) {
                    onLoadDataListener.fail(error)
                }
            })
    }
    fun startSearch(str: String,onLoadDataListener: OnLoadDataListener){
        var params: HashMap<String, String> = hashMapOf()
        params.put("location", str)
        params.put("key", Constant.key)
        RequestManager().doGet(Constant.url_search, null, params)
            .execute(object : BaseCallBack<CitySearchList>(CitySearchList::class.java) {
                override fun success(call: Call?, data: CitySearchList) {
                    onLoadDataListener.success(data)
                }

                override fun fail(error: String) {
                    onLoadDataListener.fail(error)
                }
            })
    }
}